package org.cosmos.modules.web.msg;

import org.apache.commons.lang.StringUtils;

/**
 * @author fisher
 * @description Ajax消息工具类
 */

public class AjaxMsgUtils {

	private static AjaxMsgUtils instance = new AjaxMsgUtils();
	private AjaxMsg ajaxMsg = new AjaxMsg();

	private AjaxMsgUtils() {
		ajaxMsg = new AjaxMsg();
	}

	public static AjaxMsg build(String message, String code, Object datas) {
		instance.ajaxMsg.setMessage(message);
		instance.ajaxMsg.setCode(code);
		instance.ajaxMsg.setDatas(datas);

		return instance.ajaxMsg;

	}

	public static AjaxMsg build(Object datas) {

		instance.ajaxMsg.setCode(AjaxMsg.SUCCESS);
		instance.ajaxMsg.setDatas(datas);
		instance.ajaxMsg.setMessage(StringUtils.EMPTY);

		return instance.ajaxMsg;
	}

	public static AjaxMsg build(String message) {

		instance.ajaxMsg.setMessage(message);
		instance.ajaxMsg.setDatas(null);
		instance.ajaxMsg.setCode(AjaxMsg.FAILURE);

		return instance.ajaxMsg;

	}
}
